<!DOCTYPE html>  
<html>

<head>
    <meta charset="utf-8">
    <title>js练习</title>
</head>
<body>
    <!-- 三角形 -->
    <script>
        function triangle(){
        var length=prompt("请输入你想要打印三角形的行数：");
        for (let a = 1; a <= length; a++) {
            for (let b = 0; b < length - a; b++) {              //打印空格
                document.write("&nbsp;");
            }
            for (let c = 1; c <= a * 2 - 1; c++) {         //打印星星
                document.write("*");
            }
            document.write("<br>");                       //控制每次打印完当前行然后换行
        }
    }
    triangle();
    </script>
    <h4>-----------------------------------------</h4>
    <!-- 平行四边形 -->
    <script>
        function rhomboid(){
        var length=prompt("请输入你想要打印平行四边形的行数：");
        for (let a = 1; a <= length; a++) {
            for (let b = a; b <= length; b++) {                //打印空格
                document.write("&nbsp;");
            }
            for (let c = 0; c < 8; c++) {                 //打印星星
                document.write("*");
            }
            document.write("<br>");                      //控制每次打印完当前行然后换行
        }
    }
    rhomboid();
    </script>
    
</body>
</html><!DOCTYPE html>  
<html>
